package action.member;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import service.MemberService;
import util.PagingBean;
import vo.MemberListVO;
import vo.MemberVO;


public class MemberListAction {
	private MemberService member_service;
	private MemberListVO lvo;
	
	public MemberService getMemberService() {return member_service;}
	public void setMemberService(MemberService member_service) {this.member_service = member_service;}
		public MemberListVO getLvo() {return lvo;}
	public void setLvo(MemberListVO lvo) {this.lvo = lvo;}
	
	public String execute(){
		HttpServletRequest request = ServletActionContext.getRequest();
		
		int page = 0;
		try{
			page = Integer.parseInt(request.getParameter("page"));
		}catch(NumberFormatException e){
			
		}
		ArrayList<MemberVO> list = new ArrayList<MemberVO>();
		
		if (page==0){
			list = member_service.getList(1);
		}else{
			list = member_service.getList(page);
		}
		int totalCount = member_service.selectTotalCount();
		PagingBean pagingBean = new PagingBean(totalCount, 1);
		int a = pagingBean.getStartPageOfPageGroup();
		System.out.println("page : " + a);
		lvo = new MemberListVO(list, pagingBean);
		System.out.println(list);
		request.setAttribute("list", list);
		request.setAttribute("lvo", lvo);
		
		return "success";
	}
}
